package homework;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

public class YanZhengMa {
    public static void main(String[] args) {
        //定义数组然后将字母传入数组中
        char[] ch = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
        //定义随机数
        Random r = new Random();

        //定义集合保存验证码
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            //定义字符串数组保存验证码
            char[] yzm = new char[6];
            for (int j = 0; j < yzm.length; j++) {
                yzm[j] = ch[r.nextInt(ch.length)];
            }
            //拼接字符串
            list.add(String.valueOf(yzm));
        }
        for (String s : list) {
            System.out.println("随机验证码："+s);
        }


//        //使用迭代器输出
//        Iterator<String> it = list.iterator();
//        while ((it.hasNext())){
//            System.out.println("随机验证码："+it.next());
//        }
    }
}
